Repository navigation
fix(coding-agent): build forks atomically and keep a header write's prefix - #4305
Open
code-yeongyu wants to merge 4 commits into
Open
code-yeongyu wants to merge 4 commits into
code-yeongyu wants to merge 4 commits into
Conversation
This was referenced Oct 26, 2026
code-yeongyu
marked this pull request as ready for review
October 26, 2026 03:09
Co-authored-by: sisyphus-dev-ai <sisyphus-dev-ai@users.noreply.github.com>
main's torn-tail recovery (#4295: back up and report a torn tail) and the transcript journal (#4272) are folded into this branch's session write state: - the flushed state's tailFailure carries a SessionRecoveryCause; a torn tail found on open whose backup was refused rides the buffered state as deferredTail until the load completes; - truncateToLastCompleteLine keeps main's backup and report, and takes the header catch-up's known durable boundary without a backup (those bytes are re-written from memory); - the transcript journal counts the file as persisted only when no catch-up entries are still owed (_fileHoldsMemory); - the every-offset torn test runs one case per byte offset: each cut is now set aside through the fsynced backup writer.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4295
Summary
forkFromis atomic. The fork is built throughreplaceFileAtomically(temp file in the same directory, fsync, rename) instead of an exclusive header write followed by oneappendFileSyncper entry. A full disk part-way through now leaves no half-copied fork in the session list. The fork's name carries a fresh timestamp and session id, as before; no extra existence probe is added, because the RPC session path's no-sync audit admits no new blocking call. The two retiredforkFromledger entries (writeFileSync,appendFileSync) are removed._writeHeaderAsyncwrites the header and the first entries through an exclusive handle, then appends entries persisted while that handle closed. When that catch-up append failed, the cleanup deleted the whole new file, including the header and the entries already on disk. Now the file is kept and cut back to the bytes known whole, the transcript counts as flushed, and the entries the failed append carried are written, one line each, before the next append. A failure while the exclusive handle is still open removes the part-written file as before (fix(coding-agent): a refused delivery, header or release write never leaves a session stuck #2370).createBranchedSessionalready writes through the atomic_rewriteFile(fix(coding-agent): rewrite session files atomically so a failed migration keeps the original #2367). Its full-disk case is added as a guard test.Evidence
main96f8ac1:fork-full-disk.test.ts(three half-copied forks left behind) and the newsession-manager-header-write.test.tscase (expected [] to deeply equal [ 'session', 'before' ]).test/session-manager(all files),session-manager-header-writeandsession-append-refused-mid-turn, 234/234.tsc --noEmit,oxlint,oxfmt --check, lint ratchet and the changelog gate pass.fs/fs/promisesmocks with a byte budget); no real disk was filled.Merge order (with bugwatch)
#4297 (A1) -> #4303 (B) -> #4300 (A2) -> #4305 (C) last. #4305 touches the same flushed-append block in
SessionManager._persistas #4300, so it rebases after #4300 merges. #4305 carriesFixes #4295; the others arePart of #4295.Follow-up
host-lifecycle.jsthree times per file run, so its test 3 can time out on a heavily loaded host. That is unrelated to this change and is tracked there, not folded here.